#include "EmptyKvTableFixture.h"

class QueryFile : public FileDBWithEmptyTable {
public:
  void TearDown(const ::benchmark::State & state) override{
	}
};
BENCHMARK_DEFINE_F(QueryFile, SYNC_OFF_WAL_80K)(::benchmark::State & state) {
  action("PRAGMA synchronous = OFF;");
  action("PRAGMA journal_mode = WAL;");
  action("PRAGMA cache_size = 128000;");

	//prepare 1000M 
	size_t insertCount = state.range(0);
	insert(insertCount);
	assert(count() == insertCount);

	std::string offset = std::to_string(state.range(1));
	std::string limit = std::to_string(state.range(2));
	assert(10 == count("select count(1) from (select 1 from tab1 limit 10 offset 0);"));

	std::string sql;
	sql.append("select rowid, * from tab1 ")
		.append(" order by rowid desc")
		.append(" limit ").append(limit)
		.append(" offset ").append(offset)
		;
  for(auto _ : state){
		query(sql);
  }
}

BENCHMARK_REGISTER_F(QueryFile, SYNC_OFF_WAL_80K)
  ->Unit(benchmark::kMillisecond)
	->Args({1000*1000, 1000*400, 100})
  ->Iterations(10);
